<?php

$dom = new DOMDocument();

foreach ($playlist as $id3) {

    $songlist = $dom->appendChild($dom->createElement('songlist'));
        $song = $songlist->appendChild($dom->createElement('song'));

            $image = $song->appendChild($dom->createElement('image'));
            $image->appendChild($dom->createTextNode('image.jpg'));
            $artist = $song->appendChild($dom->createElement('artist'));
            $artist->appendChild($dom->createTextNode('Artist'));
            $title = $song->appendChild($dom->createElement('title'));
            $title->appendChild($dom->createTextNode('Title'));
            $track = $song->appendChild($dom->createElement('track'));
            $track->appendChild($dom->createTextNode('Track'));
            $year = $song->appendChild($dom->createElement('year'));
            $year->appendChild($dom->createTextNode('Year'));
            $album = $song->appendChild($dom->createElement('album'));
            $album->appendChild($dom->createTextNode('Album'));
}

$dom->formatOutput = true;
echo $dom->save('./prueba.xml');

?>
